package com.xinou.daily_report.expand.sso;

import com.xinou.daily_report.expand.sso.mini.MiniFilter;
import com.xinou.daily_report.expand.sso.mini.MiniRealm;
import com.xinou.sso.config.shiro.customize.CustomizeFilterBean;
import com.xinou.sso.config.shiro.customize.CustomizeFilterService;
import lombok.RequiredArgsConstructor;
import org.apache.shiro.realm.Realm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.List;

/**
 * xx<br>
 *
 * @author lizhongyuan
 * @date 2021/6/21
 */
@Component
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class CustomizeFilterServiceImpl implements CustomizeFilterService {

    private final MiniRealm miniRealm;

    @Override
    public List<CustomizeFilterBean> filters() {
        CustomizeFilterBean customizeFilterBean = new CustomizeFilterBean();
        customizeFilterBean.setFilerName("miniFilter");
        customizeFilterBean.setFilter(new MiniFilter());
        customizeFilterBean.setFilterRang("/mini/**");
        return Collections.singletonList(customizeFilterBean);
    }

    @Override
    public List<Realm> realms() {
        return Collections.singletonList(miniRealm);
    }

    @Override
    public void clearAuthenticationInfo(Long userId) {
        miniRealm.clearAuthenticationInfo(userId);
    }

    @Override
    public void clearAuthorizationInfo(Long userId) {
        miniRealm.clearAuthorizationInfo(userId);
    }

    @Override
    public void clearAuthorizationAll() {
        miniRealm.clearAuthorizationAll();
    }

    @Override
    public void clearAuthenticationAll() {
        miniRealm.clearAuthenticationAll();
    }

}
